#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QLabel* label = new QLabel(ui->tab);
    label->setText("标签页1");
    label->resize(100,50);
    QLabel* label2 = new QLabel(ui->tab_2);
    label2->setText("标签页2");
    label2->resize(100,50);

    connect(ui->tabWidget,&QTabWidget::tabCloseRequested,this,&Widget::deleteTab);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::deleteTab(int index)
{
    ui->tabWidget->removeTab(index);
}


void Widget::on_pushButton_add_clicked()
{
    int count = ui->tabWidget->count();
    QWidget* w = new QWidget();
    ui->tabWidget->addTab(w,QString("Tab")+QString::number(count+1));

    QLabel* label = new QLabel(w);
    label->setText(QString("标签页")+QString::number(count+1));
    label->resize(100,50);
}

void Widget::on_pushButton_del_clicked()
{
    int index = ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(index);
}
